
package com.ami.kvm.jviewer;

import java.awt.Dimension;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Locale;
import java.util.Set;
import java.util.TreeSet;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import javax.swing.JComponent;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

import com.ami.kvm.jviewer.gui.JViewerApp;
import com.ami.kvm.jviewer.gui.LocaleStrings;
import com.ami.kvm.jviewer.gui.StandAloneConnectionDialog;
import com.ami.vmedia.VMApp;

public class JViewer {
	public static final String APP_TYPE_JVIEWER = "JViewer";
	public static final String APP_TYPE_VMAPP = "VMApp";
	public static final String APP_TYPE_PLAYER = "PlayVideo";
	public static final String APP_TYPE_DOWNLOAD_SAVE = "SaveVideo";
	public static final String APP_TYPE_STAND_ALONE = "StandAlone";
	public static final String APP_TYPE_WEB_PREVIEW = "WebPreview";
	public static final String APP_TYPE_BSOD_VIEWER = "BSODScreen";
	public static final String DEFAULT_LOCALE = "EN";
	public static final int HTTPS_PORT = 443;
	public static final int INVALID_PORT = -1;
	public static final int MIN_FRAME_WIDTH = 800;
	public static final int MIN_FRAME_HEIGHT = 600;
	public static final int EXT_PRIV_UNDEF = -1;
	public static final int KVM_DEF_RECONN_RETRY = 12;
	public static final int KVM_DEF_RECONN_INTERVAL = 10;
	public static final int MEDIA_SERVICE_ENABLED = 1;
	public static final byte KVM_ENABLED = 0;
	public static final byte VMEDIA_ENABLED = 1;
	public static final byte POWER_OPTION_PRIV = 8;
	public static final int LICENSED = 1;
	public static final String AUTO_DETECT_KEYBOARD = "AD";
	private static String OPTION_USAGE = LocaleStrings.getString("1_2_JVIEWER") + "JViewer.jar"
			+ " < -apptype StandAlone> < -hostname " + LocaleStrings.getString("S_2_SACD") + " > < -u "
			+ LocaleStrings.getString("S_4_SACD") + " > < -p " + LocaleStrings.getString("S_5_SACD") + "> < -webport "
			+ LocaleStrings.getString("S_3_SACD") + "> <-localization/-lang " + LocaleStrings.getString("S_21_SACD")
			+ "> <-launch " + LocaleStrings.getString("S_34_SACD") + ">";

	private static JFrame mainFrame;

	private static JDesktopPane mainPane;

	private static String apptype = "JViewer";// TODO tianlin

	private static boolean standalone;

	private static String title = "JViewer";
	private static String ip;
	private static byte[] ServerIp;
	private static int kvmPort = 7578;
	private static int SecureChannel = 0;
	private static int VMSecureChannel = 0;
	private static int cdserver_port = 0;
	private static int fdserver_port = 0;
	private static int hdserver_port = 0;
	private static byte Num_CD = 1;
	private static byte Num_FD = 1;
	private static byte Num_HD = 1;
	private static int CD_State = 0;
	private static int FD_State = 0;
	private static int HD_State = 0;
	private static boolean useSSL = false;
	private static boolean VMUseSSL = false;
	private static String webSessionToken = null;
	private static String kvmToken = null;
	private static int kvmTokenType = 0;
	private static String lang = null;
	private static int webPort = -1;
	private static int webSecure = 0;
	private static String keyboardLayout = "AD";
	private static String[] videoFile = null;
	private static boolean isKVMReconnectEnabled = false;
	private static int retryCount = 12;
	private static int retryInterval = 10;
	private static String username = null;
	private static String password = null;

	private static String launch = null;
	private static boolean isSinglePortEnabled = false;
	private static int argLength = 0;
	private static int kvmPrivilege = -1;
	private static boolean unknownParam = false;
	private static String unknownParams = "";
	private static long OEMFeatureStatus = 0L;
	private static byte KVMLicenseStatus = 0;
	private static byte MediaLicenseStatus = 0;
	private static boolean isClientAdmin = false;
	private static byte KVM_Num_CD = 1;
	private static byte KVM_Num_FD = 1;
	private static byte KVM_Num_HD = 1;
	private static byte powerSaveMode = 0;

	private static final Set<String> KEYBOARD_LAYOUTS = new HashSet(
			Arrays.asList(new String[] { "AD", "US", "GB", "FR", "FR-BE", "DE", "DE-CH", "JP", "ES", "IT", "DA", "FI",
					"NO", "PT", "SV", "NL-NL", "NL-BE", "TR_F", "TR_Q" }));

	private static boolean restService = false;

	private static boolean defaultlang = false;

	// mark by tianlin
	public static void main(String[] paramArrayOfString) {
		mainFrame = new JFrame("JViewer");
		mainFrame.setMinimumSize(new Dimension(800, 600));
		mainFrame.setDefaultCloseOperation(0);
		standalone = true;
		argLength = paramArrayOfString.length;

		ParseCmd(paramArrayOfString);
		if (lang == null) {
			setLanguage("EN");

			setDefaultLang(true);
		}
		if (apptype == null) {
			apptype = "StandAlone";
		}
		if ((!isStandAloneApp()) && (!isBSODViewer()) && (!isWebPreviewer()) && (!isStandAloneSupportedApps(apptype))) {

			JOptionPane.showMessageDialog(null, LocaleStrings.getString("1_4_JVIEWER"),
					LocaleStrings.getString("S_9_SACD"), 0);
		}

		if ((!isStandAloneApp()) && (isStandAloneSupportedApps(getLaunch()))) {
			JOptionPane.showMessageDialog(null, LocaleStrings.getString("1_1_JVIEWER"),
					LocaleStrings.getString("S_9_SACD"), 0);

			exit(0);
		}
		if (paramArrayOfString.length > 0) {
			Debug.out.println("JViewer Arguments\n");
			for (int i = 0; i < paramArrayOfString.length - 1; i += 2) {
				Debug.out.println(paramArrayOfString[i] + " : " + paramArrayOfString[(i + 1)]);
			}
		}

		if ((getOEMFeatureStatus() & 0x80) == 128L) {
			VMApp.getInstance().setNumCD(KVM_Num_CD);
			VMApp.getInstance().setNumFD(KVM_Num_FD);
			VMApp.getInstance().setNumHD(KVM_Num_HD);
		}
		setIsClientAdmin(isClientUserAdmin());
		if (isjviewerapp()) {
			JViewerApp.getInstance().getConnection().setWebSSLVerify(false);
			Debug.out.println("JViewer Application Initialised");
			redirect();
		} else if (isplayerapp()) {
			Debug.out.println("Player Application  Initialised");
			recording();
		} else if (isdownloadapp()) {
			Debug.out.println("Download and save Application  Initialised");
			recording();
		} else if (isStandAloneApp()) {
			Debug.out.println("Stand Alone Application  Initialised");
			launchStandAlone();
		} else if (isVMApp()) {
			launchStandAlone();

		} else {
			printUsage();
		}
	}

	public static boolean isjviewerapp() {
		if ((apptype != null) && (apptype.compareToIgnoreCase("JViewer") == 0)) {
			return true;
		}

		return false;
	}

	public static boolean isplayerapp() {
		if ((apptype != null) && (apptype.compareToIgnoreCase("PlayVideo") == 0)) {
			return true;
		}

		return false;
	}

	public static boolean isdownloadapp() {
		if ((apptype != null) && (apptype.compareToIgnoreCase("SaveVideo") == 0)) {
			return true;
		}

		return false;
	}

	public static boolean IsBitSet(int paramInt1, int paramInt2) {
		return (paramInt1 & 1 << paramInt2) != 0;
	}

	public static boolean isStandAloneApp() {
		if ((apptype != null) && (apptype.compareToIgnoreCase("StandAlone") == 0)) {
			return true;
		}

		return false;
	}

	public static String getIp() {
		return ip;
	}

	public static String getLaunch() {
		return launch;
	}

	public static boolean isDefaultLang() {
		return defaultlang;
	}

	public static void setDefaultLang(boolean paramBoolean) {
		defaultlang = paramBoolean;
	}

	public static boolean isStandAloneSupportedApps(String paramString) {
		if ((paramString != null) && ((paramString.compareToIgnoreCase("JViewer") == 0)
				|| (paramString.compareToIgnoreCase("PlayVideo") == 0)
				|| (paramString.compareToIgnoreCase("SaveVideo") == 0)
				|| (paramString.compareToIgnoreCase("VMApp") == 0))) {

			return true;
		}

		return false;
	}

	public static void launch(JFrame paramJFrame, JDesktopPane paramJDesktopPane, String[] paramArrayOfString) {
		standalone = false;
		mainFrame = paramJFrame;
		mainPane = paramJDesktopPane;
		redirect();
	}

	public static void recording() {
		String str = Integer.toString(webPort);
		JViewerApp.getInstance().Ondisplayvideo(ip, str, webSessionToken, webSecure);
	}

	public static void launchStandAlone() {
		JViewerApp.getInstance().onLaunchStandAloneApp(ip, webPort, username, password);
	}

	public static void launchVMApp() {
		JViewerApp.getInstance().OnvMedia(0);
	}

	public static void redirect() {
		if (isKVMEnabled()) {
			if (isSinglePortEnabled() == true) {
				JViewerApp.getInstance().getConnection().setKvmSSLVerify(false);
			}
			JViewerApp.getInstance().OnConnectToServer(ip, kvmPort, kvmToken, kvmTokenType, useSSL, VMUseSSL,
					cdserver_port, fdserver_port, hdserver_port, Num_CD, Num_FD, Num_HD, CD_State, FD_State, HD_State,
					webSessionToken, webPort);

			VMApp.getInstance().createIUSBRedirectionSession();
		} else {
			JOptionPane.showMessageDialog(null, LocaleStrings.getString("1_5_JVIEWER"),
					LocaleStrings.getString("1_3_JVIEWER"), 0);
		}
	}

	public static void ParseCmd(String[] paramArrayOfString) {
		int i = 0;
		int j = -1;
		String str = null;
		while ((i < paramArrayOfString.length) && (paramArrayOfString[i].startsWith("-"))) {
			try {
				str = paramArrayOfString[(i++)];

				if ((str.contains("-oem"))
						&& (JViewerApp.getOEMManager().handleOemArguments(paramArrayOfString, i) == 1)) {
					continue;
				}

				if (str.equals("-apptype")) {
					if (i < paramArrayOfString.length) {
						apptype = paramArrayOfString[(i++)];
					} else {
						System.err.println("-apptype" + LocaleStrings.getString("1_4_JVIEWER"));
					}
				} else if (str.equals("-launch")) {
					if (i < paramArrayOfString.length) {
						launch = paramArrayOfString[(i++)];

						if (!isStandAloneSupportedApps(launch)) {
							JOptionPane.showMessageDialog(null, LocaleStrings.getString("1_1_JVIEWER") + " -launch",
									LocaleStrings.getString("S_9_SACD"), 0);

							printUsage();
						}

					}
				} else if (str.equals("-title")) {
					if (paramArrayOfString[i] != null) {
						title = paramArrayOfString[i];
					} else
						title = "JViewer";
					i++;

				} else if (str.equals("-hostname")) {
					ip = paramArrayOfString[i];
					ServerIp = getServerIP(paramArrayOfString[(i++)]);
					if ((ServerIp == null) && (!isStandAloneApp())) {
						printUsage();

					}

				} else if (str.equals("-kvmtoken")) {
					try {
						kvmToken = paramArrayOfString[(i++)];
					} catch (NumberFormatException localNumberFormatException1) {
						Debug.out.println(localNumberFormatException1);
						printUsage();
						return;
					}

				} else if (str.equals("-kvmtokentype")) {
					try {
						kvmTokenType = Integer.parseInt(paramArrayOfString[(i++)]);
					} catch (NumberFormatException localNumberFormatException2) {
						Debug.out.println(localNumberFormatException2);
						printUsage();
						return;
					}
				} else if (str.equals("-kvmsecure")) {
					try {
						SecureChannel = Integer.parseInt(paramArrayOfString[(i++)]);
						if ((SecureChannel != 0) && (SecureChannel != 1)) {
							printUsage();
							return;
						}
						useSSL = SecureChannel == 1;
					} catch (NumberFormatException localNumberFormatException3) {
						Debug.out.println(localNumberFormatException3);
						printUsage();
						return;
					}
				}

				else if (str.equals("-kvmport")) {
					try {
						kvmPort = Integer.parseInt(paramArrayOfString[(i++)]);
					} catch (NumberFormatException localNumberFormatException4) {
						Debug.out.println(localNumberFormatException4);
						printUsage();
						return;
					}
				} else if (str.equals("-vmsecure")) {
					try {
						VMSecureChannel = Integer.parseInt(paramArrayOfString[(i++)]);
						if ((VMSecureChannel != 0) && (VMSecureChannel != 1)) {
							printUsage();
							return;
						}
						VMUseSSL = VMSecureChannel == 1;
					} catch (NumberFormatException localNumberFormatException5) {
						Debug.out.println(localNumberFormatException5);
						printUsage();
						return;
					}
				}

				else if (str.equals("-cdstate")) {
					try {
						CD_State = Integer.parseInt(paramArrayOfString[(i++)]);
					} catch (NumberFormatException localNumberFormatException6) {
						Debug.out.println(localNumberFormatException6);
						printUsage();
						return;
					}

				} else if (str.equals("-cdport")) {
					try {
						cdserver_port = Integer.parseInt(paramArrayOfString[(i++)]);
					} catch (NumberFormatException localNumberFormatException7) {
						Debug.out.println(localNumberFormatException7);
						printUsage();
						return;
					}

				} else if (str.equals("-cdnum")) {
					try {
						Num_CD = (byte) Integer.parseInt(paramArrayOfString[(i++)]);

						VMApp.getInstance().setNumCD(Num_CD);
					} catch (NumberFormatException localNumberFormatException8) {
						printUsage();
						return;
					}

				} else if (str.equals("-fdstate")) {
					try {
						FD_State = Integer.parseInt(paramArrayOfString[(i++)]);
					} catch (NumberFormatException localNumberFormatException9) {
						Debug.out.println(localNumberFormatException9);
						printUsage();
						return;
					}

				} else if (str.equals("-fdport")) {
					try {
						fdserver_port = Integer.parseInt(paramArrayOfString[(i++)]);
					} catch (NumberFormatException localNumberFormatException10) {
						Debug.out.println(localNumberFormatException10);
						printUsage();
						return;
					}

				} else if (str.equals("-fdnum")) {
					try {
						Num_FD = (byte) Integer.parseInt(paramArrayOfString[(i++)]);

						VMApp.getInstance().setNumFD(Num_FD);
					} catch (NumberFormatException localNumberFormatException11) {
						printUsage();
						return;
					}

				} else if (str.equals("-hdstate")) {
					try {
						HD_State = Integer.parseInt(paramArrayOfString[(i++)]);
					} catch (NumberFormatException localNumberFormatException12) {
						printUsage();
						return;
					}

				} else if (str.equals("-hdport")) {
					try {
						hdserver_port = Integer.parseInt(paramArrayOfString[(i++)]);
					} catch (NumberFormatException localNumberFormatException13) {
						printUsage();
						return;
					}

				} else if (str.equals("-hdnum")) {
					try {
						Num_HD = (byte) Integer.parseInt(paramArrayOfString[(i++)]);

						VMApp.getInstance().setNumHD(Num_HD);
					} catch (NumberFormatException localNumberFormatException14) {
						Debug.out.println(localNumberFormatException14);
						printUsage();
						return;
					}

				} else if ((str.equals("-localization")) || (str.equals("-lang"))) {
					lang = paramArrayOfString[(i++)];
					if ((lang.equals(null)) || (lang.length() == 0)) {
						if (isStandAloneApp()) {
							JOptionPane.showMessageDialog(null,
									LocaleStrings.getString("1_1_JVIEWER") + str + " !!!\n" + OPTION_USAGE,
									LocaleStrings.getString("1_3_JVIEWER"), 0);
						}

						printUsage();
						return;
					}

					if ((Arrays.asList(paramArrayOfString).contains("-localization"))
							&& (Arrays.asList(paramArrayOfString).contains("-lang"))) {
						JOptionPane.showMessageDialog(null,
								LocaleStrings.getString("1_8_JVIEWER") + " -localization / -lang",
								LocaleStrings.getString("A_5_GLOBAL"), 0);

						exit(0);
					}
					setLanguage(lang.toUpperCase());

				} else if (str.equals("-webcookie")) {
					try {
						webSessionToken = paramArrayOfString[(i++)];
					} catch (NumberFormatException localNumberFormatException15) {
						Debug.out.println(localNumberFormatException15);
						printUsage();
						return;
					}

				} else if (str.equals("-websecure")) {
					try {
						webSecure = Integer.parseInt(paramArrayOfString[(i++)]);
					} catch (NumberFormatException localNumberFormatException16) {
						Debug.out.println(localNumberFormatException16);
						printUsage();
						return;
					}

				} else if (str.equals("-webport")) {
					webPort = getWebPortNumber(paramArrayOfString[(i++)]);
				} else if (str.equals("-keyboardlayout")) {
					keyboardLayout = paramArrayOfString[(i++)];

				} else if (str.equals("-retrycount")) {
					try {
						setRetryCount(Integer.parseInt(paramArrayOfString[(i++)]));
					} catch (NumberFormatException localNumberFormatException17) {
						printUsage();
						return;
					}

				} else if (str.equals("-retryinterval")) {
					try {
						setRetryInterval(Integer.parseInt(paramArrayOfString[(i++)]));
					} catch (NumberFormatException localNumberFormatException18) {
						printUsage();
						return;
					}

				} else if (str.equals("-videofile")) {
					try {
						if (videoFile == null)
							videoFile = new String[1];
						videoFile[0] = paramArrayOfString[(i++)];
					} catch (NumberFormatException localNumberFormatException19) {
						Debug.out.println(localNumberFormatException19);
						printUsage();
						return;
					}

				} else if (str.equalsIgnoreCase("-u")) {
					username = paramArrayOfString[(i++)];
				} else if (str.equalsIgnoreCase("-p")) {
					int localNumberFormatException19 = i++;
					try {
						if (!paramArrayOfString[localNumberFormatException19].startsWith("-")) {
							password = paramArrayOfString[localNumberFormatException19];
						} else {
							i--;
						}
					} catch (Exception localException2) {
					}
				} else if (str.equals("-singleportenabled")) {
					try {
						j = Integer.parseInt(paramArrayOfString[(i++)]);
						if ((j != 0) && (j != 1)) {
							printUsage();
							return;
						}
						isSinglePortEnabled = j == 1;
					} catch (NumberFormatException localNumberFormatException20) {
						Debug.out.println(localNumberFormatException20);
						printUsage();
						return;
					}
				} else if (str.equals("-extendedpriv")) {
					kvmPrivilege = Integer.parseInt(paramArrayOfString[(i++)]);

				} else if (str.equals("-kvmcdnum")) {
					try {
						KVM_Num_CD = (byte) Integer.parseInt(paramArrayOfString[(i++)]);
					} catch (NumberFormatException localNumberFormatException21) {
						printUsage();
						return;
					}

				} else if (str.equals("-kvmfdnum")) {
					try {
						KVM_Num_FD = (byte) Integer.parseInt(paramArrayOfString[(i++)]);
					} catch (NumberFormatException localNumberFormatException22) {
						printUsage();
						return;
					}

				} else if (str.equals("-kvmhdnum")) {
					try {
						KVM_Num_HD = (byte) Integer.parseInt(paramArrayOfString[(i++)]);
					} catch (NumberFormatException localNumberFormatException23) {
						printUsage();
						return;
					}
				} else if (str.equals("-powersavemode")) {
					try {
						powerSaveMode = (byte) Integer.parseInt(paramArrayOfString[(i++)]);
					} catch (NumberFormatException localNumberFormatException24) {
						printUsage();
						return;
					}
				} else {
					unknownParam = true;
					if (unknownParams.length() <= 0) {
						unknownParams += str;
					} else
						unknownParams = unknownParams + ", " + str;
					printUsage();
					i++;
				}
			} catch (Exception localException1) {
				Debug.out.println(localException1);
				if (isStandAloneApp()) {
					JOptionPane.showMessageDialog(null,
							LocaleStrings.getString("1_1_JVIEWER") + str + " !!!\n" + OPTION_USAGE,
							LocaleStrings.getString("1_3_JVIEWER"), 0);
				}

				printUsage();
			}

			if (Collections.frequency(Arrays.asList(paramArrayOfString), str) > 1) {
				JOptionPane.showMessageDialog(null, LocaleStrings.getString("1_8_JVIEWER") + " " + str,
						LocaleStrings.getString("A_5_GLOBAL"), 0);

				exit(0);
			}
		}

		if (((isStandAloneApp()) || (apptype == null)) && (unknownParams.length() > 0)) {
			JOptionPane.showMessageDialog(null,
					LocaleStrings.getString("1_1_JVIEWER") + unknownParams + " !!!\n" + OPTION_USAGE,
					LocaleStrings.getString("1_1_JVIEWER"), 1);
		}
	}

	public static void printUsage() {
		if ((isStandAloneApp()) || (apptype == null)) {
			Debug.out.println(OPTION_USAGE);
		} else {
			Debug.out.println("Invalid arguments, please try again");
			Debug.out.println(
					"Usage: java -jar JViewer.jar <apptype> <ip address> <KVM port number> <token> <ssl for KVM> <ssl for vmedia> <Number of parallel Floppy Redirection> <Number of parallel CD/DVD Redirection>  <Number of parallel Hard disk Redirection> <cdserver port> <fdserver port> <hdserver port> <user privileges> <language> <token>");

			Debug.out.println(
					"<apptype> JViewer for JViewer App,Player for playing the video,SAveVideo for download and save video in cleint system");

			Debug.out.println("<ssl for KVM> 1 for secure connection and 0 for non-secure ");

			Debug.out.println("<ssl for vmedia> 1 for secure connection and 0 for non-secure ");

			Debug.out.println("<user privileges> ");
			Debug.out.println("                  0x00000020 - VKVM permissions only");

			Debug.out.println("                  0x00000040 - VMedia permissions only");

			Debug.out.println("                  0x00000060 - VKVM & VMedia permissions");

			Debug.out.println("<language> ");
			Debug.out.println("                  EN - English");
		}
		if (isStandalone()) {
			if (!unknownParam) {
				exit(0);
			} else {
				unknownParam = false;
			}
		} else {
			JViewerApp.getInstance().getMainWindow().dispose();
		}
	}

	public static byte[] getServerIP(String paramString) {
		byte[] arrayOfByte = null;
		try {
			ip = paramString;
			InetAddress localInetAddress = InetAddress.getByName(paramString);
			paramString = localInetAddress.getHostAddress();
			arrayOfByte = InetAddress.getByName(paramString).getAddress();
			Debug.out.println("Resolving to IPAddress " + paramString);

			for (int i = 0; i < arrayOfByte.length; i++)
				Debug.out.print(Byte.valueOf(arrayOfByte[i]));
		} catch (UnknownHostException localUnknownHostException) {
			ip = null;
			Debug.out.println("Error Resolving IP address");
			Debug.out.println(localUnknownHostException);
		}

		return arrayOfByte;
	}

	public static void setServerIP(byte[] paramArrayOfByte) {
		ServerIp = paramArrayOfByte;
	}

	public static JFrame getMainFrame() {
		return mainFrame;
	}

	public static void setMainFrame(JFrame paramJFrame) {
		mainFrame = paramJFrame;
	}

	public static JDesktopPane getMainPane() {
		return mainPane;
	}

	public static void setMainPane(JDesktopPane paramJDesktopPane) {
		mainPane = paramJDesktopPane;
	}

	public static boolean isStandalone() {
		return standalone;
	}

	public static void setStandalone(boolean paramBoolean) {
		standalone = paramBoolean;
	}

	public static void setIp(String paramString) {
		ip = paramString;
	}

	public static void setKVMPort(int paramInt) {
		kvmPort = paramInt;
	}

	public static String getKVMToken() {
		return kvmToken;
	}

	public static void setSessionCookies(String paramString) {
		kvmToken = paramString;
	}

	public static String getWebSessionToken() {
		return webSessionToken;
	}

	public static void setWebSessionToken(String paramString) {
		webSessionToken = paramString;
	}

	public static void setSecureChannel(int paramInt) {
		SecureChannel = paramInt;
	}

	public static void setVMSecureChannel(int paramInt) {
		VMSecureChannel = paramInt;
	}

	public static int getCDPort() {
		return cdserver_port;
	}

	public static void setCdserver_port(int paramInt) {
		cdserver_port = paramInt;
	}

	public static int getFDPort() {
		return fdserver_port;
	}

	public static void setFdserver_port(int paramInt) {
		fdserver_port = paramInt;
	}

	public static int getHDPort() {
		return hdserver_port;
	}

	public static void setHdserver_port(int paramInt) {
		hdserver_port = paramInt;
	}

	public static boolean isKVMReconnectEnabled() {
		return isKVMReconnectEnabled;
	}

	public static void setKVMReconnectEnabled(boolean paramBoolean) {
		isKVMReconnectEnabled = paramBoolean;
	}

	public static int getRetryCount() {
		return retryCount;
	}

	public static void setRetryCount(int paramInt) {
		retryCount = paramInt;
	}

	public static int getRetryInterval() {
		return retryInterval;
	}

	public static void setRetryInterval(int paramInt) {
		retryInterval = paramInt * 1000;
	}

	public static byte getNum_CD() {
		return Num_CD;
	}

	public static byte getNum_FD() {
		return Num_FD;
	}

	public static byte getNum_HD() {
		return Num_HD;
	}

	public static void setNum_CD(byte paramByte) {
		Num_CD = paramByte;
		if ((getOEMFeatureStatus() & 0x80) != 128L) {
			VMApp.getInstance().setNumCD(paramByte);
		}
	}

	public static void setNum_FD(byte paramByte) {
		Num_FD = paramByte;
		if ((getOEMFeatureStatus() & 0x80) != 128L) {
			VMApp.getInstance().setNumFD(paramByte);
		}
	}

	public static void setNum_HD(byte paramByte) {
		Num_HD = paramByte;
		if ((getOEMFeatureStatus() & 0x80) != 128L) {
			VMApp.getInstance().setNumHD(paramByte);
		}
	}

	public static int getCDState() {
		return CD_State;
	}

	public static void setCD_State(int paramInt) {
		CD_State = paramInt;
	}

	public static boolean isCdServiceEnabled() {
		return CD_State == 1;
	}

	public static int getFDState() {
		return FD_State;
	}

	public static void setFD_State(int paramInt) {
		FD_State = paramInt;
	}

	public static boolean isFdServiceEnabled() {
		return FD_State == 1;
	}

	public static int getHDState() {
		return HD_State;
	}

	public static void setHD_State(int paramInt) {
		HD_State = paramInt;
	}

	public static boolean isHdServiceEnabled() {
		return HD_State == 1;
	}

	public static boolean isUseSSL() {
		return useSSL;
	}

	public static void setUseSSL(boolean paramBoolean) {
		useSSL = paramBoolean;
	}

	public static boolean isVMUseSSL() {
		return VMUseSSL;
	}

	public static void setVMUseSSL(boolean paramBoolean) {
		VMUseSSL = paramBoolean;
	}

	public static String getLanguage() {
		return lang;
	}

	public static void setLanguage(String paramString) {
		try {
			if (!getSupportedLocaleCodes().contains(paramString)) {
				Debug.out.println("Language isn't available: " + getLanguage());
				JOptionPane.showMessageDialog(null, LocaleStrings.getString("AC_4_LS"),
						LocaleStrings.getString("AC_1_LS"), 0);

				paramString = "EN";

				setDefaultLang(true);
			}
		} catch (Exception localException) {
			Debug.out.printError(localException);
			paramString = "EN";
		}

		lang = paramString;
		LocaleStrings.setLanguageID(lang);

		StandAloneConnectionDialog.setSelectedLocale(lang);

		JComponent.setDefaultLocale(new Locale(lang.toLowerCase()));
	}

	public static int getArgLength() {
		return argLength;
	}

	public static int getWebPortNumber(String paramString) {
		int i;
		try {
			i = Integer.parseInt(paramString);
		} catch (NumberFormatException localNumberFormatException) {
			i = -1;
			Debug.out.println("Invalid port number");
			Debug.out.println(localNumberFormatException);
		}
		return i;
	}

	public static void setWebPort(int paramInt) {
		webPort = paramInt;
	}

	public static boolean isSinglePortEnabled() {
		return isSinglePortEnabled;
	}

	public static void setSinglePortEnabled(boolean paramBoolean) {
		isSinglePortEnabled = paramBoolean;
	}

	public static void setApptype(String paramString) {
		apptype = paramString;
	}

	public static boolean isWebPreviewer() {
		if ((apptype != null) && (apptype.compareToIgnoreCase("WebPreview") == 0)) {
			return true;
		}

		return false;
	}

	public static boolean isBSODViewer() {
		if ((apptype != null) && (apptype.compareToIgnoreCase("BSODScreen") == 0)) {
			return true;
		}

		return false;
	}

	public static String getKeyboardLayout() {
		return keyboardLayout;
	}

	public static void setKeyboardLayout(String paramString) {
		if (KEYBOARD_LAYOUTS.contains(paramString)) {
			keyboardLayout = paramString;
		} else
			keyboardLayout = "AD";
	}

	public static String[] getVideoFile() {
		return videoFile;
	}

	public static void setVideoFile(String[] paramArrayOfString) {
		videoFile = paramArrayOfString;
	}

	public static int getKVMPrivilege() {
		return kvmPrivilege;
	}

	public static void setKVMPrivilege(int paramInt) {
		kvmPrivilege = paramInt;
	}

	public static boolean isKVMEnabled() {
		return IsBitSet(kvmPrivilege, 0);
	}

	public static boolean isVMediaEnabled() {
		return IsBitSet(kvmPrivilege, 1);
	}

	public static boolean isPowerPrivEnabled() {
		return IsBitSet(kvmPrivilege, 8);
	}

	public static String getTitle() {
		return title;
	}

	public static long getOEMFeatureStatus() {
		return OEMFeatureStatus;
	}

	public static void setOEMFeatureStatus(long paramLong) {
		OEMFeatureStatus = paramLong;
	}

	public static byte getKVMLicenseStatus() {
		return KVMLicenseStatus;
	}

	public static void setKVMLicenseStatus(byte paramByte) {
		KVMLicenseStatus = paramByte;
	}

	public static byte getMediaLicenseStatus() {
		return MediaLicenseStatus;
	}

	public static void setMediaLicenseStatus(byte paramByte) {
		MediaLicenseStatus = paramByte;
	}

	public static int getWebSecure() {
		return webSecure;
	}

	public static boolean isWebSecure() {
		return getWebSecure() == 1;
	}

	public static void setWebSecure(int paramInt) {
		webSecure = paramInt;
	}

	public static void exit(int paramInt) {
		if (Debug.MODE == 0)
			Debug.out.closeLog();
		System.exit(paramInt);
	}

	public static void setIsClientAdmin(boolean paramBoolean) {
		isClientAdmin = paramBoolean;
	}

	public static boolean IsClientAdmin() {
		return isClientAdmin;
	}

	private static boolean isClientUserAdmin() {
		boolean bool = false;
		String str1 = System.getProperty("os.name");
		String str2 = null;
		Object localObject;
		if (str1.startsWith("Windows")) {
			str2 = "reg query \"HKU\\S-1-5-19\"";
		} else if (str1.startsWith("Linux")) {
			localObject = System.getProperty("user.name");
			str2 = "id -u " + (String) localObject;
		} else if (str1.startsWith("Mac")) {
			bool = true;
		}
		if (str2 == null) {
			return bool;
		}
		try {
			localObject = Runtime.getRuntime().exec(str2);
			((Process) localObject).waitFor();
			int i = ((Process) localObject).exitValue();
			if (str1.startsWith("Windows")) {
				if (0 == i) {
					bool = true;
				}
			} else if ((str1.startsWith("Linux")) || (str1.startsWith("Mac"))) {
				BufferedReader localBufferedReader = new BufferedReader(
						new InputStreamReader(((Process) localObject).getInputStream()));

				String str3 = null;
				while ((str3 = localBufferedReader.readLine()) != null) {
					if (str3.equals("0")) {
						bool = true;
					}
				}

				localBufferedReader.close();
			}
		} catch (Exception localException) {
			Debug.out.println("Not able find client user privilege");
		}
		return bool;
	}

	public static byte getKVM_Num_CD() {
		return KVM_Num_CD;
	}

	public static void setKVM_Num_CD(byte paramByte) {
		KVM_Num_CD = paramByte;
		if ((getOEMFeatureStatus() & 0x80) == 128L) {
			VMApp.getInstance().setNumCD(paramByte);
		}
	}

	public static byte getKVM_Num_FD() {
		return KVM_Num_FD;
	}

	public static void setKVM_Num_FD(byte paramByte) {
		KVM_Num_FD = paramByte;
		if ((getOEMFeatureStatus() & 0x80) == 128L) {
			VMApp.getInstance().setNumFD(paramByte);
		}
	}

	public static byte getKVM_Num_HD() {
		return KVM_Num_HD;
	}

	public static void setKVM_Num_HD(byte paramByte) {
		KVM_Num_HD = paramByte;
		if ((getOEMFeatureStatus() & 0x80) == 128L) {
			VMApp.getInstance().setNumHD(paramByte);
		}
	}

	public static byte getPowerSaveMode() {
		return powerSaveMode;
	}

	public static void setPowerSaveMode(byte paramByte) {
		powerSaveMode = paramByte;
	}

	public static boolean isPowerSaveModeEnabled() {
		return getPowerSaveMode() == 1;
	}

	public static String getUsername() {
		return username;
	}

	public static void setUsername(String paramString) {
		username = paramString;
	}

	public static String getPassword() {
		return password;
	}

	public static void setPassword(String paramString) {
		password = paramString;
	}

	public static int getWebPort() {
		return webPort;
	}

	public static boolean isVMApp() {
		if ((apptype != null) && (apptype.compareToIgnoreCase("VMApp") == 0)) {
			return true;
		}

		return false;
	}

	public static int getKvmPort() {
		return kvmPort;
	}

	public static boolean isRestService() {
		return restService;
	}

	public static void setRestService(boolean paramBoolean) {
		restService = paramBoolean;
	}

	public static boolean isUnknownArgs() {
		return unknownParams.length() > 0;
	}

	public static String[] getSupportedLocales() {
		String[] arrayOfString = { "English - [EN]" };
		ArrayList localArrayList1 = getClassesNames("com.ami.kvm.jviewer.oem.lang");
		ArrayList localArrayList2 = getClassesNames("com.ami.kvm.jviewer.soc.lang");
		if (!localArrayList1.isEmpty()) {
			Object[] arrayOfObject1 = localArrayList1.toArray();
			java.awt.List localList = new java.awt.List();
			for (Object localObject : arrayOfObject1) {

				String str1 = (String) localObject;
				str1 = str1.substring(str1.indexOf("Resources"));

				int k = localArrayList2.indexOf(
						"com.ami.kvm.jviewer.soc.lang.SOC" + str1.substring(str1.lastIndexOf('.') + 1, str1.length()));

				if (k >= 0) {
					if (str1.startsWith("Resources_", str1.lastIndexOf('.') + 1)) {
						int m = str1.lastIndexOf('_') + 1;
						int n = str1.length();
						String str2 = str1.substring(m, n);
						Locale localLocale = new Locale(str2.toLowerCase());

						String str3 = localLocale.getDisplayLanguage(localLocale);
						localList.add(str3 + " - [" + str2 + "]");
					}
				} else {
					Debug.out.printError("Resource bundle : com.ami.kvm.jviewer.soc.lang.SOC"
							+ str1.substring(str1.lastIndexOf('.') + 1, str1.length()) + " is not available!!!");
				}
			}

			arrayOfString = localList.getItems();
		}
		return arrayOfString;
	}

	public static ArrayList<String> getSupportedLocaleCodes() {
		String[] arrayOfString1 = getSupportedLocales();
		ArrayList localArrayList = new ArrayList();
		try {
			for (String str : arrayOfString1) {
				int k = str.indexOf(" - [");
				int m = str.indexOf("]");

				if ((k != -1) && (m != -1))
					localArrayList.add(str.substring(k + " - [".length(), m));
			}
			if (localArrayList.isEmpty()) {
				localArrayList.add("EN");
			}
		} catch (Exception localException) {
			Debug.out.printError(localException);
			localArrayList.add("EN");
		}
		return localArrayList;
	}

	public static ArrayList<String> getClassesNames(String paramString) {
		try {
			ClassLoader localClassLoader = Thread.currentThread().getContextClassLoader();
			assert (localClassLoader != null);
			String str1 = paramString.replace('.', '/');
			Enumeration localEnumeration = localClassLoader.getResources(str1);
			ArrayList localArrayList = new ArrayList();
			while (localEnumeration.hasMoreElements()) {
				URL localObject1 = (URL) localEnumeration.nextElement();
				localArrayList.add(((URL) localObject1).getFile());
			}
			Object localObject1 = new TreeSet();
			for (Object localObject2 = localArrayList.iterator(); ((Iterator) localObject2).hasNext();) {
				String localObject3 = (String) ((Iterator) localObject2).next();
				((TreeSet) localObject1).addAll(findClasses((String) localObject3, paramString));
			}
			ArrayList localObject2 = new ArrayList();
			for (Object localObject3 = ((TreeSet) localObject1).iterator(); ((Iterator) localObject3).hasNext();) {
				String str2 = (String) ((Iterator) localObject3).next();
				((ArrayList) localObject2).add(str2);
			}
			return (ArrayList<String>) localObject2;
		} catch (IOException localIOException) {
			Debug.out.println(localIOException);
		}
		return null;
	}

	private static TreeSet<String> findClasses(String paramString1, String paramString2) {
		TreeSet localTreeSet = new TreeSet();

		Object localObject3;

		if ((Debug.MODE == 2) || (Debug.MODE == 0)) {
			if (paramString1.contains("!")) {
				String[] localObject1 = paramString1.split("!");
				Object localObject2 = null;
				try {
					localObject2 = new URL(localObject1[0]);
				} catch (MalformedURLException localMalformedURLException) {
					Debug.out.println(localMalformedURLException);
				}
				localObject3 = null;
				try {
					localObject3 = new ZipInputStream(((URL) localObject2).openStream());
				} catch (IOException localIOException1) {
					Debug.out.println(localIOException1);
				}
				ZipEntry localZipEntry = null;
				try {
					while ((localZipEntry = ((ZipInputStream) localObject3).getNextEntry()) != null) {
						if (localZipEntry.getName().endsWith(".class")) {
							String str = localZipEntry.getName().replaceAll("[$].*", "").replaceAll("[.]class", "")
									.replace('/', '.');

							if (str.contains(paramString2)) {
								localTreeSet.add(str);
							}
						}
					}
				} catch (IOException localIOException2) {
					Debug.out.println(localIOException2);

				}

			}

		} else if (Debug.MODE == 1) {
			if ((System.getProperty("os.name").startsWith("Windows")) && (paramString1.startsWith("/"))) {
				paramString1 = paramString1.substring(paramString1.indexOf('/') + 1, paramString1.length());
			}

			if (paramString1.contains("%20")) {
				if (System.getProperty("os.name").startsWith("Windows")) {
					paramString1 = paramString1.replaceAll("%20", " ");
				} else {
					paramString1 = paramString1.replaceAll("%20", "\\ ");
				}
			}
		}
		Object localObject1 = new File(paramString1);
		if (!((File) localObject1).exists()) {
			return localTreeSet;
		}
		File[] localObject2 = ((File) localObject1).listFiles();
		for (Object localObject4 : localObject2) {
			if (((File) localObject4).isDirectory()) {
				assert (!((File) localObject4).getName().contains("."));
				localTreeSet.addAll(findClasses(((File) localObject4).getAbsolutePath(),
						paramString2 + "." + ((File) localObject4).getName()));
			} else if (((File) localObject4).getName().endsWith(".class")) {
				localTreeSet.add(paramString2 + '.'
						+ ((File) localObject4).getName().substring(0, ((File) localObject4).getName().length() - 6));
			}
		}
		return localTreeSet;
	}
}